﻿namespace MicroCloud.AspNetCore.Mvc.ModelBinding
{
    /// <summary>
    /// <see cref="StringTrimModelBinder"/>提供者，提供对字符串前后空白进行Trim操作的模型绑定能力
    /// </summary>
    public class StringTrimModelBinderProvider : IModelBinderProvider
    {
        #region 方法
        /// <summary>
        /// 基于<see cref="ModelBinderProviderContext" />创建<see cref="IModelBinder" />
        /// </summary>
        /// <param name="context">The <see cref="ModelBinderProviderContext" /></param>
        /// <returns>An <see cref="IModelBinder" /></returns>
        public IModelBinder GetBinder(ModelBinderProviderContext context)
        {
            Check.NotNull(context, nameof(context));

            if (context.Metadata.UnderlyingOrModelType == typeof(string))
            {
                return new StringTrimModelBinder();
            }
            return null;
        }

        #endregion

    }

}
